package logic

import (
	"context"
	"storage/models"

	"storage/internal/svc"
	"storage/pb/storage"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateFileLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFileLogic {
	return &CreateFileLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateFile 创建文件
func (l *CreateFileLogic) CreateFile(in *storage.FileInfo) (*storage.Empty, error) {
	_, err := l.svcCtx.FilesModel.Insert(l.ctx, &models.Files{
		UserId:   in.UserId,
		FileName: in.FileName,
		ParentId: in.ParentId,
		FileType: in.FileType,
		FileExt:  in.FileExt,
		FileSize: in.FileSize,
		FileHash: in.FileHash,
		FilePath: in.FilePath,
		Status:   in.Status,
	})
	if err != nil {
		return nil, err
	}
	return &storage.Empty{}, nil
}
